package org.example.backend.controller;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.Instant;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataResult implements Serializable {
    private Integer code;
    private Object data;
    private String msg;
    private Long timeStamp;

    // 返回带数据DataResult对象
    public static DataResult success(Object data) {
        return new DataResult(200,data, "操作成功", Instant.now().toEpochMilli());
    }
    // 返回不带数据DataResult对象
    public static DataResult success(){
        return new DataResult(200, null, "操作成功",Instant.now().toEpochMilli());
    }
    // 返回错误DataResult对象
    public static DataResult error(String msg) {
        return new DataResult(500, null, msg,Instant.now().toEpochMilli());
    }
}
